package com.choudou5.solr.analyzer;

import com.choudou5.solr.analyzer.filter.PinyinNGramTokenFilter;
import com.choudou5.solr.analyzer.filter.PinyinTransformTokenFilter;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer;
import org.wltea.analyzer.lucene.IKTokenizer;

import java.io.Reader;


public class PinyinNGramAnalyzer extends Analyzer {

    public Analyzer.TokenStreamComponents createComponents(String fieldName, Reader reader)
    {
        Tokenizer tokenizer = new IKTokenizer(reader, false);
        TokenStream result = (TokenStream)tokenizer;
        result = new PinyinTransformTokenFilter(result, 2);
        result = new PinyinNGramTokenFilter(result, 2, 20);
        return new Analyzer.TokenStreamComponents(tokenizer, result);
    }
}
